home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / btrieve / btrvph.c < prev    next >
Text File  |  1991-08-19  |  6KB  |  144 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*           WatCom C interface to the Btrieve Record Manager               */
  4. /*                                                                          */
  5. /*  Watcom v8.0 interface for use with Phar Lap 4.0                         */
  6. /*  By Adam White                                                           */
  7. /*     Westinghouse Canada Inc.                                             */
  8. /*     416-528-8811 ext 3420                                                */
  9. /*                                                                          */
  10. /*  Configure Phar Lap with 64K callbufs                                    */
  11. /*  ie: CFIG386 RUN386 -callbufs 64                                         */
  12. /*                                                                          */
  13. /*  Call BTRVinstalled() to determine if btrieve is installed               */
  14. /*--------------------------------------------------------------------------*/
  15. #define BTR_ERR     20                        /* record manager not started */
  16. #define BTR_INT     0x7B                        /* Btrieve interrupt vector */
  17. #define BTR_OFFSET  0x33                   /* Btrieve offset within segment */
  18. #define VARIABLE_ID 0x6176         /* id for variable length records - 'va' */
  19. int BTRVerr;                                           /* global error flag */
  20.  
  21. #include <stdio.h>  
  22. #include <stdlib.h>
  23. #include <string.h> 
  24. #include <malloc.h>
  25. #include <dos.h>
  26.  
  27. typedef unsigned short int INT;
  28. #define SINT short
  29.  
  30. typedef struct                /* structure passed to Btrieve Record Manager */
  31. {
  32.   char     *bufAddress;                      /* callers data buffer Address */
  33.   INT      bufLength;                              /* length of data buffer */
  34.   char     *curAddress;                      /* user position block Address */
  35.   char     *fcbAddress;                              /* Address of disk FCB */
  36.   INT      function;                                  /* requested function */
  37.   char     *keyAddress;                     /* Address of user's key buffer */
  38.   char     keyLength;                        /* length of user's key buffer */
  39.   char     keyNumber;                       /* key of reference for request */
  40.   INT      *statAddress;                          /* Address of status word */
  41.   INT      xfaceID;                                  /* language identifier */
  42. } BTRIEVE_PARMS;
  43.  
  44. typedef struct  {                               /* Phar Lap parameter block */
  45.       INT itrpt;
  46.       INT ds;
  47.       INT es;
  48.       INT fs;
  49.       INT gs;
  50.       int eax;
  51.       int edx; } PARM_BLOCK;
  52.  
  53. int BTRV (int operation,char *posBlock,char *dataBuf,int *dataLen,char *keyBuf,int keyNum)
  54. {
  55.    union REGS regs;
  56.    struct SREGS sregs;
  57.    BTRIEVE_PARMS __far *xData;
  58.    PARM_BLOCK pblock;
  59.    char __far *interModeBuffer;
  60.    char __far *protModeCallBufFCB;
  61.    char __far *protModeCallBufDataBuf;
  62.    char __far *protModeCallBufKeyBuf;
  63.    int bufferUsed=0,realModeBufferAddress;
  64.    INT __far *stat;                               /* status of Btrieve call */
  65.  
  66. /*                                                                      */
  67. /*  Move user parameters to xData, the block where Btrieve expects them.*/
  68. /*                                                                      */
  69.    segread(&sregs);
  70.    regs.x.eax=0x250D;           /* get address of call buffer from Phar Lap */
  71.    int386x(0x21, ®s, ®s, &sregs);
  72.    interModeBuffer=MK_FP(sregs.es,regs.x.edx);
  73.    realModeBufferAddress=regs.x.ebx;
  74.                         
  75.    xData=(BTRIEVE_PARMS __far *) interModeBuffer;
  76.    xData->function    = operation;
  77.    xData->bufLength   = *dataLen;
  78.    xData->keyLength   = 255;                 /* use max since we don't know */
  79.    xData->keyNumber   = keyNum;
  80.    xData->xfaceID     = VARIABLE_ID;
  81.    bufferUsed=sizeof(*xData);
  82.  
  83. /* all pointers and the data pointed to must appear in the callbuf */
  84.  
  85.    stat=(INT __far *) interModeBuffer+bufferUsed;
  86.    *stat=1;
  87.    xData->statAddress = (INT *) realModeBufferAddress+bufferUsed;
  88.    bufferUsed+=sizeof(INT);
  89.  
  90.    _fmemcpy(interModeBuffer+bufferUsed,(char __far *) posBlock,128);
  91.    protModeCallBufFCB=interModeBuffer+bufferUsed;
  92.    xData->fcbAddress =(char *) realModeBufferAddress+bufferUsed;
  93.    xData->curAddress =(char *) realModeBufferAddress+bufferUsed + 38;
  94.    bufferUsed+=128;
  95.  
  96.    _fmemcpy(interModeBuffer+bufferUsed,(char __far *) dataBuf,*dataLen);
  97.    protModeCallBufDataBuf=interModeBuffer+bufferUsed;
  98.    xData->bufAddress =(char *) realModeBufferAddress+bufferUsed;
  99.    bufferUsed+=*dataLen;
  100.  
  101.    _fmemcpy(interModeBuffer+bufferUsed,(char __far *) keyBuf,255);
  102.    protModeCallBufKeyBuf=interModeBuffer+bufferUsed;
  103.    xData->keyAddress =(char *) realModeBufferAddress+bufferUsed;
  104.    bufferUsed+=255;
  105.    
  106. /*                                                                      */
  107. /*  Make call to the Btrieve Record Manager.                            */
  108. /*                                                                      */
  109.    pblock.itrpt=BTR_INT;
  110.    pblock.ds=realModeBufferAddress>>16;
  111.    pblock.edx=realModeBufferAddress;
  112.    regs.x.eax=0x2511;
  113.    segread (&sregs);
  114.    regs.x.edx=FP_OFF((char __far *) &pblock);
  115.    sregs.ds=FP_SEG((char __far *) &pblock);
  116.    int386x(0x21, ®s, ®s, &sregs);
  117.  
  118. /* copy data back to prot. mode memory */
  119.    _fmemcpy((char __far *) posBlock,protModeCallBufFCB,128);
  120.    _fmemcpy((char __far *) dataBuf,protModeCallBufDataBuf,xData->bufLength);
  121.    _fmemcpy((char __far *) keyBuf,protModeCallBufKeyBuf,xData->keyLength);
  122.  
  123.    *dataLen = xData->bufLength;
  124.    return(BTRVerr=*stat);                                  /* return status */
  125. }
  126.  
  127. /* This function determines if Btrieve has been installed */
  128. /* returns 1 if installed else 0 */
  129. /* call this fuction before making any btrieve calls */
  130. BTRVinstalled()
  131. {
  132.    int retval=0;
  133.    union REGS regs;
  134.    struct SREGS sregs;
  135.  
  136.    segread (&sregs);
  137.    regs.x.eax=0x2503;
  138.    regs.x.ecx=BTR_INT;
  139.    int386x(0x21, ®s, ®s, &sregs);
  140.    if(regs.w.bx==BTR_OFFSET)
  141.       retval=1;
  142.    return(retval);
  143. }
  144.